<?php require_once $_SERVER['DOCUMENT_ROOT'] . '/accHestia/src/svr/com/fea/stringMisc.php'; ?>
<?php require_once $_SERVER['DOCUMENT_ROOT'] . '/accHestia/src/svr/com/acc_conn.php'; ?>

<?php 
    function dorpc_autogen_prj($data, &$res) {
        $genCnt = $data["genCount"];//要生成的个数
        $ret = '<table style="width:80%"><tr><th>id</th> <th>辅助码</th> <th>项目名</th> </tr>';
        $w_str = "";
        for($i = 1; $i <= $genCnt; ++$i) {
            $w_str .= "insert into prjects(id, abbr, name) values(" . $i . ", 'xm" . $i . "', 'Dummy项目" . $i . "');\r\n";
            if($i % 2) {
                $ret .= "<tr><td>" . $i . "</td> <td>xm" . $i . "</td> <td>Dummy项目" . $i . "</td></tr>\r\n";
            } else {
                $ret .= "<tr class='acc_ood_row'><td>" . $i . "</td> <td>xm" . $i . "</td> <td>Dummy项目" . $i . "</td></tr>\r\n";
            }
        }
        $ret .= "</table>";
        
        $fpath = $_SERVER['DOCUMENT_ROOT'] . "/accHestia/db/test/prjDummy.sql";
        $f = fopen($fpath, "w");
        if(!$f) {
            set_res_NG($res, "failed on creating file: " . $fpath);
            return;
        }
        fwrite($f, $w_str);
        fclose($f);

        $res["hData"] = $ret;
        set_res_OK($res);
    }
    
    function dorpc_add_gened_prj($data, &$res) {
        $fpath = $_SERVER['DOCUMENT_ROOT'] . "/accHestia/db/test/prjDummy.sql";
        $sqlArr = file($fpath);
        $sql_cnt = count($sqlArr);
        
        
        $db = new acc_DB();
        for($i = 0; $i < $sql_cnt; $i++) {
            $ssql = rtrim($sqlArr[$i]);
            if (!$db->query($ssql)) {
                set_res_NG($res, $ssql);
                return;
            }
        }
        $res["ok_count"] = $sql_cnt;
        set_res_OK($res);
    }
?>